﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using DoAnTN.Entity;
namespace DoAnTN.Buissiness
{
    class PhongDAO
    {
        //public DataTable selectPhong() {
        //    SqlConnection conn = null;
        //    DBUtil objDB = new DBUtil();
        //    conn = objDB.connect();
        //    SqlDataAdapter dataAdapter = new SqlDataAdapter("select * from Phong",conn);
        //    DataTable dataTable = new DataTable();
        //    dataAdapter.Fill(dataTable);
        //    return dataTable;
        //}
        private static SqlConnection conn = null;
        private static DBUtil objDB = new DBUtil();
        private static Phong objPhong = null;

        public static string[,] SoDoPhong() {
            string[,] phong = new string[100, 100];
            conn = objDB.connect();
            int soTang = SoTangDAO.soTang();
            for (int i = 0; i <= soTang; i++)
            {
                conn.Open();
                int j = 1;
                SqlCommand sqlCommand = new SqlCommand("select TenPhong from Phong where MaTang="+i+"order by TenPhong asc",conn);
                SqlDataReader dataReader = sqlCommand.ExecuteReader();
                while (dataReader.Read())
                {
                    phong[i, j] = dataReader.GetValue(0).ToString();
                    j++;
                }
                conn.Close();
            }
            return phong;
        }

        public static Color MauSac(string tePhong) {
            conn = objDB.connect();
            conn.Open();
            SqlCommand objCmd = new SqlCommand("select TinhTrang from Phong where TenPhong='" + tePhong + "'", conn);
            SqlDataReader dataReader = objCmd.ExecuteReader();
            Color color = new Color();
            while (dataReader.Read())
            {
                int TinhTrang = Int32.Parse(dataReader.GetValue(0).ToString());
                if (TinhTrang == 0)
                {
                    color = Color.Green;
                }
                else if(TinhTrang == 1)
                {
                    color = Color.Red;
                }
                else if (TinhTrang == 2)
                {
                    color = Color.Yellow;
                }
                else
                {
                    color = Color.Black;
                }
            }
            conn.Close();
            return color;
        }

        public static int TongSoPhong() {
            int count = 0;
            conn = objDB.connect();
            conn.Open();
            SqlCommand objCmd = new SqlCommand("select * from Phong", conn);
            SqlDataReader dataReader = objCmd.ExecuteReader();
            while (dataReader.Read())
            {
                count++;
            }
            conn.Close();
            return count;
        }

        public static int soPhongCuaTang(int maTang) {
            int count = 0;
            conn = objDB.connect();
            conn.Open();
            SqlCommand objCmd = new SqlCommand("select * from Phong where MaTang=" + maTang, conn);
            SqlDataReader dataReader = objCmd.ExecuteReader();
            while (dataReader.Read())
            {
                count++;
            }
            conn.Close();
            return count;
        }

        public static string maLoaiPhong(string tenPhong) {
            String maLoaiPhong =null;
            conn = objDB.connect();
            conn.Open();
            SqlCommand objCmd = new SqlCommand("select MaLoaiPhong from Phong where TenPhong='"+tenPhong+"'", conn);
            SqlDataReader dataReader = objCmd.ExecuteReader();
            while (dataReader.Read())
            {
                maLoaiPhong = dataReader.GetValue(0).ToString();
            }
            conn.Close();
            return maLoaiPhong;
        }
    }
}
